package com.biboheart.breport.dataset.handler;

import com.biboheart.breport.core.BrContext;
import com.biboheart.breport.dataset.BrReport;
import com.biboheart.breport.dataset.BrReportHandler;
import com.biboheart.breport.dataset.report.BrReportDefault;
import com.biboheart.breport.template.BrTemplateStruct;

import java.util.List;
import java.util.Map;

public class BrReportHandlerDefault implements BrReportHandler {

    @Override
    public BrReport handle(BrContext context, List<Map<String, Object>> dataList, BrTemplateStruct templateStruct) {
        BrReportDefault report = new BrReportDefault(context);
        report.generateCols(templateStruct);
        int i = 0;
        for (Map<String, Object> data : dataList) {
            data.put("_index", i++);
            report.projection(data);
        }
        return report;
    }
}
